package org.example.struct.array2;

/**
 * @author liyishan
 * @date 2024/5/8 10:28
 * @apiNote
 */

public class Test002079WateringPlants {
    public static void main(String[] args) {
        int[] plants = {2,2,3,3};
        int capacity = 5;
        System.out.println(wateringPlants(plants, capacity));
    }
    public static int wateringPlants(int[] plants, int capacity) {
        int step = 0;
        int total = capacity;
        for (int i = 0; i < plants.length; i++) {
            if(capacity >= plants[i]){
                step++;
                capacity -= plants[i];
            }else{
                step += i*2+1;
                capacity =total - plants[i];
            }
        }
        return step;
    }
}
